#include "MenuCriteriosDeBusqueda.h"

MenuCriteriosDeBusqueda::MenuCriteriosDeBusqueda(SeleccionaPersonaCommand * comm) {
	command = comm;
	commands[0] = new PushMenuCommand(new MenuCriteriosDeComparacion(1, command));
	commands[1] = new PushMenuCommand(new MenuCriteriosDeComparacion(2, command));
	commands[2] = new PushMenuCommand(new MenuCriteriosDeComparacion(3, command));
	commands[3] = new VolverAlMenuAnteriorCommand();

	opciones[0] = new MenuItem(1,"Nombre",commands[0]);
	opciones[1] = new MenuItem(2,"Direccion",commands[1]);
	opciones[2] = new MenuItem(3,"Telefono",commands[2]);
	opciones[3] = new MenuItem(4,"Salir",commands[3]);

	for (unsigned int i = 0; i < opciones.size(); i++) {
		add(*(opciones[i]));
	}

}

MenuCriteriosDeBusqueda::~MenuCriteriosDeBusqueda() {
	delete command;
	CommandsMap::iterator endCommands = commands.end();
	for (CommandsMap::iterator it = commands.begin(); it != endCommands; ++it) {
		delete commands[(*it).first];
	}
	commands.clear();

	MenuItemsMap::iterator endMenuItems = opciones.end();
	for (MenuItemsMap::iterator it = opciones.begin(); it != endMenuItems; ++it) {
		delete opciones[(*it).first];
	}
	opciones.clear();
}

void MenuCriteriosDeBusqueda::update(){
	cout << "Menu Criterios De Busqueda" << endl << endl;
	display();
	cout << endl << "Opción: ";

	string input;
	int opcion;
	cin.clear();
	getline(cin, input);
	stringstream myStream(input);
	if (myStream >> opcion) {
		select(opcion);
	}
}

